package com.yibo.yunpicture.domain.space.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yibo.yunpicture.application.service.SpaceApplicationService;
import com.yibo.yunpicture.application.service.UserApplicationService;
import com.yibo.yunpicture.domain.space.entity.Space;
import com.yibo.yunpicture.domain.space.entity.SpaceUser;
import com.yibo.yunpicture.domain.space.service.SpaceUserDomainService;
import com.yibo.yunpicture.domain.space.valueobject.SpaceRoleEnum;
import com.yibo.yunpicture.domain.user.entity.User;
import com.yibo.yunpicture.infrastructure.exception.BusinessException;
import com.yibo.yunpicture.infrastructure.exception.ErrorCode;
import com.yibo.yunpicture.infrastructure.exception.ThrowUtils;
import com.yibo.yunpicture.infrastructure.mapper.SpaceUserMapper;
import com.yibo.yunpicture.interfaces.dto.spaceuser.SpaceUserAddDTO;
import com.yibo.yunpicture.interfaces.dto.spaceuser.SpaceUserQueryDTO;
import com.yibo.yunpicture.interfaces.vo.space.SpaceUserVO;
import com.yibo.yunpicture.interfaces.vo.space.SpaceVO;
import com.yibo.yunpicture.interfaces.vo.user.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author AdminMYB
* @createDate 2025-05-22 14:55:54
*/
@Service
public class SpaceUserDomainServiceImpl extends ServiceImpl<SpaceUserMapper, SpaceUser>
    implements SpaceUserDomainService {
    @Resource
    private UserApplicationService userApplicationService;

    @Resource
    private SpaceApplicationService spaceApplicationService;

    /**
     * 查询请求对象
     * @param spaceUserQueryDTO
     * @return
     */
    @Override
    public QueryWrapper<SpaceUser> getQueryWrapper(SpaceUserQueryDTO spaceUserQueryDTO) {
        if (spaceUserQueryDTO == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        QueryWrapper<SpaceUser> queryWrapper = new QueryWrapper<>();
        Long id = spaceUserQueryDTO.getId();
        Long userId = spaceUserQueryDTO.getUserId();
        Long spaceId = spaceUserQueryDTO.getSpaceId();
        String spaceRole = spaceUserQueryDTO.getSpaceRole();
        queryWrapper.eq(ObjUtil.isNotNull(id), "id", id);
        queryWrapper.eq(ObjUtil.isNotNull(userId), "userId", userId);
        queryWrapper.eq(ObjUtil.isNotNull(spaceId), "spaceId", spaceId);
        queryWrapper.eq(ObjUtil.isNotNull(spaceRole), "spaceRole", spaceRole);
        return queryWrapper;
    }
}




